<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\Staff;

/**
 * Class StaffTransformer.
 *
 * @package namespace App\Transformers;
 */
class StaffTransformer extends TransformerAbstract
{
    /**
     * Transform the Staff entity.
     *
     * @param \App\Models\Staff $model
     *
     * @return array
     */
    public function transform(Staff $model)
    {
        return [
            'id'         => (int) $model->id,
            'company' => $model->company,
            /* place your other model properties here */
            'name' => $model->name,
            'id_card' => $model->id_card . "&nbsp;",
            'age' => $model->age,
            'department_id' => $model->department_id,
            'dorm_id' => $model->dorm_id,
            'dorm_code' => optional($model->dorm)->code,
            'building_name' => $model->dorm_id ? $model->dorm->building->name : null,
            'department_name' => optional($model->department)->name,
            'date_enroll' => $model->date_enroll,
            'work_years' => $model->work_years,
            'position' => optional($model->staffPosition)->position,
            'card_num' => $model->card_num,
            'sex' => $model->sex ? ($model->sex == 1 ? '男' : '女') : '',
            'couple_name' => optional($model->couple)->name,
            'status' => $model->status == 1 ? '在职' : '离职',
            'phone' => $model->phone . "&nbsp;",
            'families_count' => $model->families_count,
            'latest_in_date' => $model->latest_in_date,
            'remark' => $model->remark,
            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s')
        ];
    }
}
